#include "general.h"
#include "settings.h"

#include <stdlib.h>
#include <openssl/sha.h>
#include <iostream>
#include <sstream>

namespace torrent {

std::string generateId() {
	std::string id = Settings::peerName;

	for (int i = id.length(); i < 20; ++i)
		id += random();

	return id;
}

std::string calcHash(const bencode& b) {
	std::stringstream str;
	str << b;

	return std::string((const char*)SHA1((const unsigned char*)(str.str().c_str()), str.str().length(), NULL), 20);
}

} // namespace torrent

